package com.luoqy.speedy.config;

import java.math.BigDecimal;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.beetl.ext.fn.StringUtil;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;


/**
 * @author admin
 */
public class UserSecurityInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request,  
            HttpServletResponse response, Object handler) throws Exception {  
    	Map<String,Object> user=(Map<String, Object>) request.getSession(true).getAttribute("user");
    	String token=request.getHeader("token");
//    	return true;
    	if(null==user){
    		System.err.println("null==user*********************");
    		request.getRequestDispatcher("/common/login").forward(request, response);
    		return false;
    	}else{
    		System.out.println("preHandle**********************");
            return true;
    	}

    	
    }  
  
    @Override  
    public void postHandle(HttpServletRequest request,  
            HttpServletResponse response, Object handler,  
            ModelAndView modelAndView) throws Exception {  
    	
    	System.err.println("postHandle");
    }  
  
    @Override  
    public void afterCompletion(HttpServletRequest request,  
            HttpServletResponse response, Object handler, Exception ex)  
            throws Exception {
    	System.err.println("afterCompletion");
    }  
  
} 
